Skip to content

Conversation

@itsmeichigo
Copy link
Contributor

@itsmeichigo itsmeichigo commented Oct 17, 2025

Closes WOOMOB-1524

Description

There is a crash report about a deadlock caused as part of the error handling when forcing direct requests for sites.

This deadlock is caused by updating UserDefaults inside the same queue we use for flagging site with barrier block. To be more specific, UserDefaults uses Key-Value Observing (KVO), which delivers notifications synchronously. When we write to UserDefaults inside a barrier block, the KVO observer fires before the barrier completes, and if that observer tries to access the same queue → deadlock.

The solution is to fire updates to UserDefaults to a separate serial queue to avoid blocking the concurrent queue we use for error handling.

Testing steps

It's not straightforward to reproduce the deadlock. Simply smoke testing the flow should be sufficient.

Use the test plan in pe5sF9-4Am-p2 - run TC4. Confirm that the app doesn't crash.

Testing information

  • Added a unit test to confirm the deadlock fix. The test fails before the fix.
  • Ran TC4 with simulator iPhone 17 and confirmed the app doesn't crash.

Screenshots

N/A


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@itsmeichigo itsmeichigo added this to the 23.5 ❄️ milestone Oct 17, 2025
@itsmeichigo itsmeichigo added the type: crash The worst kind of bug. label Oct 17, 2025
@dangermattic
Copy link
Collaborator

dangermattic commented Oct 17, 2025

1 Warning
⚠️ This PR is assigned to the milestone 23.5 ❄️. The due date for this milestone has already passed.
Please assign it to a milestone with a later deadline or check whether the release for this milestone has already been finished.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 17, 2025

App Icon📲 You can test the changes from this Pull Request in WooCommerce iOS Prototype by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS Prototype
Build Numberpr16256-fc11138
Version23.5
Bundle IDcom.automattic.alpha.woocommerce
Commitfc11138
Installation URL51s8jk978tktg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@itsmeichigo itsmeichigo marked this pull request as ready for review October 20, 2025 03:54
Copy link
Contributor

@adborbas adborbas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comments, otherwise works as described.

// Use dedicated serial queue for UserDefaults operations to:
// 1. Prevent race conditions where concurrent writes overwrite each other
// 2. Avoid deadlock by not using the main queue that KVO observers may need
userDefaultsQueue.async { [weak self] in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small note, as we are using async here notificationCenter might fire before the value is actually set.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I updated this in fc11138 and removed the waiting in tests.

// Use dedicated serial queue for UserDefaults operations to:
// 1. Prevent race conditions where concurrent writes overwrite each other
// 2. Avoid deadlock by not using the main queue that KVO observers may need
userDefaultsQueue.async { [weak self] in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concerc as above, clearUnsupportedFlag might return befire the value is set in UserDefault

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also done in fc11138.

@itsmeichigo itsmeichigo merged commit 7696da4 into release/23.5 Oct 20, 2025
13 checks passed
@itsmeichigo itsmeichigo deleted the woomob-1489-crash-deadlock branch October 20, 2025 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: crash The worst kind of bug.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants